package com.company.common;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * ObjectXXXStream交互的消息实体
 * @param <T> 内容的范型
 */
public class Message<T> implements Serializable {
    private T content;
    private MessageType type;
    private String receiver;
    private String sender;
    private LocalDateTime time;

    public Message(T content, MessageType type, String receiver, String sender, LocalDateTime time) {
        this.content = content;
        this.type = type;
        this.receiver = receiver;
        this.sender = sender;
        this.time = time;
    }

    public enum MessageType {
        /**
         * 注册
         */
        REGISTER,
        REGISTER_SUCCEED,
        REGISTER_FAIL,

        /**
         * 登录
         */
        LOGIN,
        LOGIN_SUCCEED,
        LOGIN_FAIL,
        CLI_EXIT,

        /**
         * 在线好友
         */
        GET_ONLINE_FRIENDS,
        RET_ONLINE_FRIENDS,

        /**
         * 普通消息
         */
        NORMAL_MSG,

        /**
         * 群发消息
         */
        GROUP_MSG,

        /**
         * 文件消息
         */
        FILE_MSG,

        /**
         * 获取离线消息/文件
         */
        GET_OFFLINE_MSG,
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public MessageType getType() {
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getSender() {
        return sender;
    }

    public void setSender(String sender) {
        this.sender = sender;
    }

    public LocalDateTime getTime() {
        return time;
    }

    public void setTime(LocalDateTime time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "Message{" +
                "content=" + content +
                ", type=" + type +
                ", receiver='" + receiver + '\'' +
                ", sender='" + sender + '\'' +
                ", time=" + time +
                '}';
    }
}
